package com.ruoyi.project.wms.inGoods.service.impl;

import java.util.List;

import com.ruoyi.project.wms.inGoods.domain.WmsInGoods;
import com.ruoyi.project.wms.inGoods.mapper.WmsInGoodsMapper;
import com.ruoyi.project.wms.inGoods.service.IWmsInGoodsService;
import com.ruoyi.project.wms.store.domain.WmsStore;
import com.ruoyi.project.wms.store.mapper.WmsStoreMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.utils.text.Convert;

import javax.annotation.Resource;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-09-30
 */
@Service
public class WmsInGoodsServiceImpl implements IWmsInGoodsService
{
    @Resource
    private WmsInGoodsMapper wmsInGoodsMapper;
    @Resource
    private WmsStoreMapper wmsStoreMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param igid 【请填写功能名称】ID
     * @return 【请填写功能名称】
     */
    @Override
    public WmsInGoods selectWmsInGoodsById(Long igid)
    {
        return wmsInGoodsMapper.selectWmsInGoodsById(igid);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param wmsInGoods 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<WmsInGoods> selectWmsInGoodsList(WmsInGoods wmsInGoods)
    {
        wmsInGoods.setIgstatus("未入库");
        return wmsInGoodsMapper.selectWmsInGoodsList(wmsInGoods);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param wmsInGoods 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertWmsInGoods(WmsInGoods wmsInGoods)
    {
        return wmsInGoodsMapper.insertWmsInGoods(wmsInGoods);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param wmsInGoods 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateWmsInGoods(WmsInGoods wmsInGoods)
    {
        return wmsInGoodsMapper.updateWmsInGoods(wmsInGoods);
    }

    /**
     * 批准入库对象
     * 
     * @param ids 需要批准的数据ID
     * @return 结果
     */
    @Override
    public int deleteWmsInGoodsByIds(String ids)
    {
        return wmsInGoodsMapper.deleteWmsInGoodsByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param igid 【请填写功能名称】ID
     * @return 结果
     */
    @Override
    public int deleteWmsInGoodsById(Long igid)
    {
        return wmsInGoodsMapper.deleteWmsInGoodsById(igid);
    }

    /**
     * 批准入库
     * @param igid
     * @return
     */
    @Override
    public int passInStore(Long igid) {
        WmsInGoods wmsInGoods = new WmsInGoods();
        wmsInGoods.setIgstatus("已入库");
        wmsInGoods.setIgid(igid);
        //修改进货单状态为已入库
        int i = wmsInGoodsMapper.updateWmsInGoods(wmsInGoods);
        //查询对应ID进货信息
        WmsInGoods wmsInGoods1 = wmsInGoodsMapper.selectWmsInGoodsById(igid);
        //查询对应名称库存信息
        WmsStore wmsStore = wmsStoreMapper.selectWmsStoreBySname(wmsInGoods1.getIgpname());
        //剩余库存数量
        Long snum = wmsStore.getSnum();
        //进货数量
        Long ignum = wmsInGoods1.getIgnum();
        WmsStore wmsStore1 = new WmsStore();
        wmsStore1.setSnum(snum+ignum);
        wmsStore1.setSid(wmsStore.getSid());
        if ((snum+ignum)<300l){
            //修改库存 不足
            wmsStore1.setSstatus("库存不足");
        }else {
            //充足
            wmsStore1.setSstatus("库存充足");
        }
        //更新库存
        wmsStoreMapper.updateWmsStore(wmsStore1);
        return i;
    }
}
